<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Seal (encrypt) data</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-random-pseudo-bytes.html">openssl_random_pseudo_bytes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-sign.html">openssl_sign</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.openssl-seal" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_seal</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">openssl_seal</span> &mdash; <span class="dc-title">Seal (encrypt) data</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-seal-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>openssl_seal</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$sealed_data</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$env_keys</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$pub_key_ids</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$method</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_seal()</strong></span> seals (encrypts)
   <em><code class="parameter">data</code></em> by using RC4 with a randomly generated
   secret key. The key is encrypted with each of the public keys
   associated with the identifiers in <em><code class="parameter">pub_key_ids</code></em>
   and each encrypted key is returned
   in <em><code class="parameter">env_keys</code></em>. This means that one can send
   sealed data to multiple recipients (provided one has obtained their
   public keys). Each recipient must receive both the sealed data and
   the envelope key that was encrypted with the recipient&#039;s public key.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-seal-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">data</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">sealed_data</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">env_keys</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">pub_key_ids</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-seal-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the length of the sealed data on success, or <strong><code>FALSE</code></strong> on error.
   If successful the sealed data is returned in
   <em><code class="parameter">sealed_data</code></em>, and the envelope keys in
   <em><code class="parameter">env_keys</code></em>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-seal-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-843">
    <p><strong>Example #1 <span class="function"><strong>openssl_seal()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$data&nbsp;is&nbsp;assumed&nbsp;to&nbsp;contain&nbsp;the&nbsp;data&nbsp;to&nbsp;be&nbsp;sealed<br /><br />//&nbsp;fetch&nbsp;public&nbsp;keys&nbsp;for&nbsp;our&nbsp;recipients,&nbsp;and&nbsp;ready&nbsp;them<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/src/openssl-0.9.6/demos/maurice/cert.pem"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cert&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8192</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pk1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_publickey</span><span style="color: #007700">(</span><span style="color: #0000BB">$cert</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;Repeat&nbsp;for&nbsp;second&nbsp;recipient<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/src/openssl-0.9.6/demos/sign/cert.pem"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cert&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8192</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pk2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_publickey</span><span style="color: #007700">(</span><span style="color: #0000BB">$cert</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;seal&nbsp;message,&nbsp;only&nbsp;owners&nbsp;of&nbsp;$pk1&nbsp;and&nbsp;$pk2&nbsp;can&nbsp;decrypt&nbsp;$sealed&nbsp;with&nbsp;keys<br />//&nbsp;$ekeys[0]&nbsp;and&nbsp;$ekeys[1]&nbsp;respectively.<br /></span><span style="color: #0000BB">openssl_seal</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sealed</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ekeys</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">$pk1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pk2</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;free&nbsp;the&nbsp;keys&nbsp;from&nbsp;memory<br /></span><span style="color: #0000BB">openssl_free_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$pk1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">openssl_free_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$pk2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-seal-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.openssl-open.html" class="function" rel="rdfs-seeAlso">openssl_open()</a> - Open sealed data</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-random-pseudo-bytes.html">openssl_random_pseudo_bytes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-sign.html">openssl_sign</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
